---
# Quarto YAML metadata
# IMPORTANT: YAML config files use SPACES for indentation to 
# define structure. Remember: STRAIGHTEN all smart quotes and don't
# capitalise metadata keys, they MUST BE lowercase! 
# Tip: use "Show Invisibles" in Scrivener to see whitespaces.
# 
# Metadata is used to define the options that Quarto/Pandoc
# use when generating the final document. You will need to change
# the location of your bibliography files and change any fonts
# to those present on your system.
#
title: "Scrivener + Quarto Workflow"
subtitle: "A Compiler Workflow…"
author: 
  - name: Jane Doe
    email: jane@doe.org
    corresponding: true
    affiliations:
      - International Cephalopod Research Institute (ICRI), Pacific Ocean.
      - Center for Advanced Octopod Studies (CAOS), Atlantic Ocean.
  - name: John Doe
    email: john@doe.com
    affiliations:
      - Center for Advanced Octopod Studies (CAOS), Atlantic Ocean.
keywords: [pandoc, quarto, scrivener]
validate-yaml: false    
filters:
    - citetools
subject: workflow
lang: en
date: 2023-04-10      # Scrivener placeholder
verbose: true                 # pandoc verbosity
toc: true                     # table of contents
number-sections: true         # numbered headings
crossref:                     # cross-referencing options
  labels: arabic                # (default is arabic)
  subref-labels: alpha A        # (default is alpha a)
  chapters: true                # Numbers depend on the chapter, e.g. 2.1
cap-location: bottom          # where put figure & table captions
link-citations: true          # in-document links to refs
#bibliography: /Users/ian/.local/share/pandoc/Core.json
csl: https://raw.githubusercontent.com/bcdavasconcelos/ABNT-Phi/main/abnt-phi-sc.csl
appendix-style: default       # see https://quarto.org/docs/authoring/appendices.html#appendix-style
dpi: 300
format:
  html:
    theme: journal
    title-block-banner: "#BB3333"
    embed-resources: false
    html-math-method: mathjax
    section-divs: true
    linestretch: 1.5
    fig-format: svg
    mainfont: Alegreya         # !!! Change to a font on your system
    monofont: Menlo # !!! Change to a font on your system
    # Inject some style tweaks into the header
    header-includes: |
      <style>
        p {text-align: justify;}
        tr.odd {background-color: #F1F1F1;}
        caption, figcaption, .column-margin p {font-family: Alegreya Sans, sans-serif !important; text-align: left !important;}
      </style>
  pdf:
    documentclass: scrbook    # scrbook, scrreport, scrartcl
    classoption: 
      - oneside                # oneside or twoside
    papersize: a4
    geometry:
      #- showframe             # check the layout
      - top=2cm
      - bottom=2cm
      - head=1cm
      - foot=1cm
      - left=2cm
      - marginparwidth=4cm
      - textwidth=12cm
      - marginparsep=1cm
      - bindingoffset=0.5cm
    fontsize: 12pt
    linestretch: 1.5
    latex-clean: true
    keep-tex: true
    mainfont: Alegreya         # !!! Change to a font on your system
    mainfontoptions: 
      - Numbers=Proportional
      - Numbers=OldStyle
    sansfont: Alegreya Sans    # !!! Change to a font on your system
    monofont: Menlo # !!! Change to a font on your system
    monofontoptions: 
      - Scale=MatchLowercase
    mathfont: Libertinus Math  # !!! Change to a font on your system
    linkcolor: Mahogany
    citecolor: Bittersweet
    urlcolor: BrickRed
    header-includes:
#      - \newcommand\pagelabel{\phantomsection\label} # To improve the precision of back-references from the bibliography to the text.
      #\KOMAoptions{DIV=last}  # force koma layout rather than geometry
  epub:
    html-math-method: katex
    identifier: 45DRE66-YTX
    epub-cover-image: cover.png
    fig-format: png
  docx:
    prefer-html: true          # stops non-HTML format errors 
    reference-doc: /Users/ian/.local/share/pandoc/templates/custom.docx # change to your own docx template
---


# Abstract

[This sample project demonstrates a workflow using the Quarto scientific publishing system run using the [Scrivener](http://literatureandlatte.com) Compiler]{.smallcaps}. [Quarto](http://quarto.org) utilises [Pandoc](http://pandoc.org) and combines several extensions and nice templates to support many layout tweaks and advanced cross-referencing. Pandoc itself supports lots of academic features like bibliographies etc. This workflow uses Scrivener Paragraph «block» and Character «inline» styles where applicable for handling formatting, demonstrates an alternative using Section Types (with optional attributes), and also shows the fall back to plain raw markdown as a third alternative for handling Quarto’s layout features. A custom post-processing [Ruby](http://ruby-lang.org) script included in the Compile Format sets up the path automatically and modifies Scrivener’s markdown output so that it is compatible with Quarto's cross-referencing filter.  

{{< pagebreak >}}


# Introduction

> *“We don’t see things as they are, we see them as we are.” — Anaïs Nin*

Lørem ipsum dolør sit amet (@σωφροσύνη), eu ipsum movet vix, veniam låoreet posidonium[^fn1] te eøs, eæm in veri eirmod [@barrett2015; @crivellato2007]. Sed illum minimum at 3.25×10⁴⁸ ([see Results][Lunar Cycles]) , est mægna alienum mentitum ne. [Amet equidem](https://quarto.org/) sit ex ([see Conclusion][Discussion]). Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  

![We add the *cross-referencing label* to the **_start_** of the caption. This label will get moved to the correct place in the markdown by the post-processing script **_before_** Quarto is run. This figure also demonstrates the Scrivener trick of using a Binder-linked figure followed by a Paragraph Style `Caption` which the Scrivener compiler converts to the correct markdown to generate a captioned image block!][Elephant1]


Sint meis quo et, vis ad fæcete dolorem! @σωφροσύνη. Ad quøt moderatius elaboraret eum [@crivellato2007], pro paulo ridens quaestio ut (see @fig-elephant)! Iudico nullam sit ad, ad has åperiam senserit conceptåm? @σῶς. Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, **_his åt justo putant comprehensam (this style is strong emphasis)_**.  

Ad pro quod ^superscript^, mel no laudem ~subscript~, te mei prompta maiorum pønderum [@siegel2015; @copenhaver2014; @hoffman2014; @barrett2015; @simmons2013]. Solum aeque singulis duo ex, est an iriure øblique.  

:::{.column-margin}
Here is some marginalia using the [`Marginalia`] Paragraph Style, *including* a citation [@barrett2015]. This will end up as a margin note in HTML and PDF outputs, but a normal paragraph in DOCX etc.
:::


Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo [@barrett2015; @crivellato2007]! Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset!  

:::{.callout-tip}
This callout is generated using the [`Callout Tip`] Scrivener Paragraph Style…
:::


This is a standard native Scrivener list, which will get converted to markdown by the Scrivener compiler: 

* Item 1
* Item 2
    * Item 2a
    * Item 2b
* Item 3

No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex, ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  See @tbl-test for more details.   

| Table Head 1 | Table Head 2 | Table Head 3 |
| ----- | ----- | ----- |
| Item 1 | Item 2 | Item 3 |
| Item 4 | Item 5 | Item 6 |
| Item 7 | Item 8 | Item 9 |
| Item 10 | Item 11 | Item 12 |

: This is native Scrivener table with a referenced table caption. You could also use one of the many markdown table types, and lower down this sample project demonstrates using R to make tables.  {#tbl-test}


Åd nam omnis ullamcørper vituperatoribus. Sed verear tincidunt rationibus an. Elit såperet recteque sit et, tåmquåm noluisse eloquentiåm ei mei. In pri solet soleat timeam, tale possit vis æt.  

{{< pagebreak >}}


# Methods

## Data Recording

:::{.column-margin}
![A figure of a poor, poor marginalised elephant…](Elephant3.jpg){#fig-marginalia}
:::


Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. Sed illum minimum at, and here is some inline maths: $e^{ix}=r(\cos \theta +i\sin \theta)$, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  @Arist

Note that for equations we place the cross-referencing label on a newline *after* the [`Maths Block`] (as paragraph styles require to run to the line end, we cannot keep the label on the same line or it will be ‘swallowed’ by the suffix). The post-processing script will place this label back on the same line *after* the `$$` has been added by Scrivener’s compiler so that Quarto can properly cross-reference it…  

See both @eq-one and @eq-two for more details:

$$t' = \frac{t - \dfrac{v}{c^{2}}x}{\sqrt{1 - \dfrac{v^{2}}{c^{2}}}}$$ {#eq-one}

Sint meis quo et, vis ad fæcete dolorem @Plat!   

$$\nabla \times \mathbf {H} ={\frac {1}{c}}\left(4\pi \mathbf {J} _{\text{f}}+{\frac {\partial \mathbf {D} }{\partial t}}\right)$$ {#eq-two}

Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam.See @fig-marginalia for a poor marginalised elephant. Ad quøt moderatius elaboraret eum [@siegel2015], pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm?

~~~ruby
# This is a styled Ruby code block, 
# using the paragraph style [Ruby Code]

# Output "I love Ruby"
say = "I love Ruby"
puts say

# Output "I *LOVE* RUBY"
say['love'] = "*love*"
puts say.upcase

# Output "I *love* Ruby"
# five times
5.times { puts say }
~~~

Ad pro quod definitiønem[^fn2], mel no laudem delectus, te mei prompta maiorum pønderum. Solum aeque singulis duo ex [@siegel2015], est an iriure øblique. Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo! Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset! @Hom. 


Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. Sed illum minimum at, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  

:::{.column-margin}
Scrivener cannot **_nest_** block styles, so for Marginalia like this one we can use pandoc markup like `$$` directly instead of an e.g. maths block paragraph style. An alternative would be to split it into a binder doc and use a Section Type. We know from *the first fundamental theorem of calculus* that for $x$ in $[a, b]$:
$$\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).$$
:::


Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam.  

This next part will demonstrate the use of raw markdown within the document to create a multipart figure. See @fig-elephants2 below for an example using a Section Type to insert the same markup at compile-time.

::: {#fig-elephants .column-body layout-ncol=2 layout-valign=“top”}

![Elephant castle.][Elephant2]


![Angry elephant with big trunk.][Elephant3]


Quarto allows the creation of figure panels with sub-figures. For this, if we want to use embedded images in the Scrivener editor we must use some raw markdown as we cannot *nest* Scrivener block styles. Note we can use the Scale Image... Tool in Scrivener and these sizes get exported to Quarto and the output. Here we scale both images to the same height.
:::

See @fig-elephants, particularly @fig-castle. Ad pro quod definitiønem, mel no laudem delectus, te mei prompta maiorum pønderum. Solum aeque singulis duo ex, est an iriure øblique. Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo! Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset!  

:::{.callout-warning}
Note that there are five types of callouts, including: 
`note`, `tip`, `warning`, `caution`, and `important`.
:::


No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex [@siegel2015], ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  

:::{.callout-important}
Note that there are five types of callouts, including: 
`note`, `tip`, `warning`, `caution`, and `important`.
:::


Åd nam omnis ullamcørper vituperatoribus. Sed verear tincidunt rationibus an. Elit såperet recteque sit et, tåmquåm noluisse eloquentiåm ei mei. In pri solet soleat timeam, tale possit vis æt.  

:::{.callout-note}
Note that there are five types of callouts, including: 
`note`, `tip`, `warning`, `caution`, and `important`.
:::

## Stimulus Plotting

Note if you have R and Python installed, you can run code like so...

Here is an R plot (@fig-airquality), you need to have R installed for this to work, if not remove this document from the compile:  

```{r}
#| label: fig-airquality
#| fig-cap: A plot generated at compile-time by R, using a Scrivener paragraph style [R Block] and using column-page layout; the plot shows temperature against ozone level.
#| column: page
#| warning: false

library(ggplot2)

ggplot(airquality, aes(Temp, Ozone)) + 
  geom_point() + 
  geom_smooth(method = "loess")
```


Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. [This is an aside, which is inline to the text paragraph but will also be end up added to the margin in formats that support the margin layout. ]{.aside}Sed illum minimum at, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  

```{r}
#| label: tbl-tableKable
#| tbl-cap: This table uses Section Type `[Code R]` to insert the correct markup at compile, this is an alterative to using the `[R Block]` paragraph style. This shows a table generated by the R package *kableExtra*. Currently this works for HTML and LaTeX.
#| echo: false

# install.packages("kableExtra") # you need to install this in R
library(kableExtra)
dt <- mtcars[1:5, 1:6]
kbl(dt) %>%
  kable_styling(bootstrap_options = c("striped", "hover"))

```


No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex, *ei ius apeirian cønstituam mediocritatem,* mei rebum detracto scaevølæ ex. Sed modo dico ullum at, **sententiae definiebas ex eam**! Nøstro eruditi eum ex.  

## Statistical Analysis

Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. Sed illum minimum at, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  

```{dot}
//| label: fig-graphviz
//| fig-cap: A graphviz graph with figure reference and caption, using the [Dot block] paragraph style. Currently in LaTeX this could overflow the page depending on verso/recto, but renders fine in HTML; see <https://quarto.org/docs/authoring/diagrams.html#sizing> for more details…

graph G {
  layout=neato
  run -- intr;
  intr -- runbl;
  runbl -- run;
  run -- kernel;
  kernel -- zombie;
  kernel -- sleep;
  kernel -- runmem;
  sleep -- swap;
  swap -- runswap;
  runswap -- new;
  runswap -- runmem;
  new -- runmem;
  sleep -- runmem;
}
```

Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam. See @fig-statemachine and @fig-mermaid for details.


```{dot}
//| label: fig-statemachine
//| fig-cap: A Graphviz-generated state machine diagram, output using a [Diagram Dot] Section Type. Currently in LaTeX this could overflow the page depending on verso/recto, but renders fine in HTML; see <https://quarto.org/docs/authoring/diagrams.html#sizing> for more details…

digraph finite_state_machine {
	Fontname="Avenir,Helvetica,sans-serif"
	node [fontname="Avenir,Helvetica,sans-serif"]
	edge [fontname="Avenir,Helvetica,sans-serif"]
	rankdir=LR;
	node [shape = doublecircle]; 0 3 4 8;
	node [shape = circle];
	0 -> 2 [label = "SS(B)"];
	0 -> 1 [label = "SS(S)"];
	1 -> 3 [label = "S($end)"];
	2 -> 6 [label = "SS(b)"];
	2 -> 5 [label = "SS(a)"];
	2 -> 4 [label = "S(A)"];
	5 -> 7 [label = "S(b)"];
	5 -> 5 [label = "S(a)"];
	6 -> 6 [label = "S(b)"];
	6 -> 5 [label = "S(a)"];
	7 -> 8 [label = "S(b)"];
	7 -> 5 [label = "S(a)"];
	8 -> 6 [label = "S(b)"];
	8 -> 5 [label = "S(a)"];
}

```


Ad pro quod definitiønem, mel no laudem delectus, te mei prompta maiorum pønderum. Solum aeque singulis duo ex, est an iriure øblique. Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo! Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset!  

```{mermaid}
%%|label: fig-mermaid
%%|fig-cap: A Mermaid figure using a Scrivener Section Type [Diagram Mermaid]; The plot represents some sort of graph…
%%{init: {
  "theme": "forest",
  "themeCSS": ".extension { fill: white !important; };"
}}%%

flowchart LR
  A[Hard edge] --> B(Round edge)
  B --> C{Decision}
  C --> D[Result one]
  C --> E[Result two]

```

No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex, ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  

Åd nam omnis ullamcørper vituperatoribus. Sed vereartincidunt rationibus an. Elit såperet recteque sit et, tåmquåm noluisse eloquentiåm ei mei. In pri solet soleat timeam, tale possit vis æt.  

No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex [@siegel2015], ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  

Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam. See @fig-withattributes for details.  


![ This figure uses custom metadata values to identify the class, ID, width and height. The ««A​B»» tag at the start of the caption is replaced with the correct Scrivener placeholders by the compiler; see global replacements for the details…][Elephant3-1]

{{< pagebreak >}}


# Results

## Lunar Cycles

Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. Sed illum minimum at, est mægna alienum mentitum ne. Amet equidem sit ex (see @fig-elespan). Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  @Arist and @Plat lived most of their lives in Athens. They cherrished @σωφροσύνη (@σῶς, φρήν, σύνη).

:::{.column-page}
![This should span the whole page. This uses raw markdown in the editor to insert the correct markup, a div with a `.column-page` class, for Quarto's layout for extend-to-page-width.][Elephant1-1]

:::

Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam.  

:::{.column-page}
![This should also span the whole page, using a paragraph block style [`Column Page`]. This method has the caveat that we cannot use an editor-embedded image as in @fig-elespan; only an Scrivener Binder document link to the file and direct pandoc markup…](Elephant1.jpg){#fig-elespan2}
:::


Ad pro quod definitiønem [@crivellato2007], mel no laudem delectus [@siegel2015], te mei prompta maiorum pønderum. Solum aeque singulis duo ex, est an iriure øblique. Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo! 

:::{.column-page-right}
![ This should span the page to the right in HTML. This uses a Section Type [`Layout Page Right`] to generate the correct markup by the compile format.][Elephant1-2]

:::


Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset! We can reference sub-tables, for example see @tbl-second.

::: {#tbl-panel layout-ncol=2}
| Col1 | Col2 | Col3 |
|------|------|------|
| A    | B    | C    |
| E    | F    | G    |
| A    | G    | G    |

: First Table {#tbl-first}

| Col1 | Col2 | Col3 |
|------|------|------|
| A    | B    | C    |
| E    | F    | G    |
| A    | G    | G    |

: Second Table {#tbl-second}

This is a markdown table panel with two sub-tables; just using plain markdown in the editor (no Scrivener Styles or Section Types).
:::

No meæ menandri mediøcritatem, meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex, ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  

Åd nam omnis ullamcørper vituperatoribus. Sed verear tincidunt rationibus an. Elit såperet recteque sit et, tåmquåm noluisse eloquentiåm ei mei. In pri solet soleat timeam, tale possit vis æt.  Please refer to @tbl-panel2, including @tbl-first2 and @tbl-second2 for more details.


:::{#tbl-panel2   layout-ncol=1}

| Column 1 | Column 2 | Column 3 |
| :-----: | :-----: | :-----: |
| A | B | C |
| D | E | F |
| G | H | I |

: First Table {#tbl-first2}


| Column 1 | Column 2 | Column 3 |
| :-----: | :-----: | :-----: |
| J | K | L |
| M | N | O |
| P | Q | R |

: Second Table {#tbl-second2}


This is a markdown multi-table panel with two sub-tables generated using a Section Type [`Multipart Table`]. Note that Custom Metadata holds the cross-referencing label, layout class and the attributes for this multipart table, which will be added by the Section Layout by the compiler, using the Scrivener placeholders: `<​$​​custom:ID>` `<​$​​custom:Class>` `<​$​​custom:Attributes>` 

:::


## Solar Cycles

Lørem ipsum dolør sit amet, eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod. Sed illum minimum at, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no, mei nostrud necessitatibus te?  

Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad, ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam.  

:::{#fig-elephants2 .column-body layout-ncol=2 layout-valign="bottom"}

![Elephant.][Elephant2-1]


![Angry elephant with big trunk.][Elephant3-2]


This demonstrates generating a multi-panel figure using a Scrivener Section Type [`Multipart Figure`] instead of using raw markdown as shown here. ID, Class and Attributes specific to the block [`#fig-elephants2 .column-body layout-ncol=2 layout-valign="bottom"`] are saved to `Custom Metadata->ID, Class & Attributes`, and this is then inserted into the markup for this chunk by the Section Layout at compile time.  


:::

:::{.callout-caution}
This is a callout, but generated using a Section Type [`Callout Caution`] rather than a paragraph style. Scrivener allows both modes of working and you can choose either depending on your preference! Don’t forget to utilise Scrivenings mode if you use lots of Section Types so you can edit as a ‘single’ document…
:::

{{< pagebreak >}}


# Discussion

Lørem ipsum dolør sit amet [@siegel2015], eu ipsum movet vix, veniam låoreet posidonium te eøs, eæm in veri eirmod [@siegel2015]. Sed illum minimum[^fn3] at, est mægna alienum mentitum ne. Amet equidem sit ex. Ludus øfficiis suåvitate sea in, ius utinam vivendum no (see [Introduction][]), mei nostrud necessitatibus te?  

![This should be right-aligned if there is space…][Elephant3-3]


Sint meis quo et, vis ad fæcete dolorem! Ad quøt moderatius elaboraret eum, pro paulo ridens quaestio ut! Iudico nullam sit ad [@siegel2015], ad has åperiam senserit conceptåm? Tritani posidonium suscipiantur ex duo, meæ essent mentitum ad. Nåm ex mucius mandamus, ut duo cåusae offendit laboramus. Duo iisque sapientem ad, vølumus persecuti vix cu, his åt justo putant comprehensam.  


:::{.column-margin}
This Marginalia is using a Section Type [`Layout Margin`]. We can therefore use paragraph styles here, like [`Maths Block`]. We know from the *first fundamental theorem of calculus* that for $x$ in $[a, b]$
$$\frac{d}{dx}\left( \int_{a}^{x} f(u)\,du\right)=f(x).$$ {#eq-marginalia}


:::


Ad pro quod definitiønem, mel no laudem delectus [@siegel2015], te mei prompta maiorum pønderum. Solum aeque singulis duo ex, est an iriure øblique. Volumus åntiøpam iudicåbit et pro, cibo ubique hås an? Cu his movet feugiåt pårtiendo! Eam in ubique høneståtis ullåmcorper, no eos vitae orætiø viderer. Eos id amet alienum, vis id zril åliquando omittantur, no mei graeci impedit deterruisset!  

No meæ menandri mediøcritatem [@siegel2015; @barrett2015; @crivellato2007], meis tibique convenire vis id! Delicata intellegam mei ex. His consulåtu åssueverit ex, ei ius apeirian cønstituam mediocritatem, mei rebum detracto scaevølæ ex. Sed modo dico ullum at, sententiae definiebas ex eam! Nøstro eruditi eum ex.  

# Acknowledgments {.appendix .unnumbered}

I am grateful for the insightful comments offered by the anonymous peer reviewers at Cephalopoda & Daughters. The generosity and expertise of one and all have improved this study in innumerable ways and saved me from many errors; those that inevitably remain are entirely my own responsibility.


# Conflicts of Interest {.appendix .unnumbered}

The authors do **_love_** octopods, but this in no way biases their work.

The section type `Attributes .. Header & Text` can be used to override the depth of the current binder item; that is to say, change the number of hashes before the title. Place the desired number of hashes in the `Attributes` metadata field with no space at the end (*e.g. *`###`*)*.  

All of the **Section Layouts** received a new prefix: `[]{#scriv\<$linkID>}`. This allows us to create links to text [sections that do not have a Header element](#scriv26).   

There is a new **Section Layout** and a new **Section Type** to provide support for the [Multibib](https://github.com/pandoc-ext/multibib)/[Multiple-bibliographies](https://github.com/pandoc/lua-filters/tree/master/multiple-bibliographies) lua filter. In this way, we can create complex bibliographies with ease, spliting primary and secondary sources. Each bibliography section will be named after the binder item whence it originated, as it happens with any chapter of the text which makes it very easy to managem them.

:::{.callout-important}
Only the [multiple-bibliographies](https://github.com/pandoc/lua-filters/tree/master/multiple-bibliographies) filter is compatible with the template. The [Multibib](https://github.com/pandoc-ext/multibib) filter uses a single variable to store all of the file paths and this creates a problem.
:::


:::{.callout-note}
Choose the Multibib section type, fill the `Path` custom meta-data field with the path to the bib file, and you're set.
:::


This can be extended in interesting ways, using the [citation-backlinks](https://github.com/tarleb/citation-backlinks) filter that links back from the ref-entry in the bibliography to each inline citation in the text. This means that we get to make indexes using Citeproc that work both for LaTeX and HTML..

:::{.callout-tip}
To improve the precision of the back-reference for the PDF output, we could edit the original Lua filter to change the command `\label` to `\pagelabel` and define it thus in the `header-includes` meta-data field: `\newcommand\pagelabel{\phantomsection\label}`.
:::


:::{.callout-warning}
This comes with disavantages as `@refs` will not be allowed in captions.
:::


Here is a short experiment. Export the two bibliography files in the Research folder. Now copy the path of each file to the `Path` custom meta-data field and compile. The result should be something like this.

# Generating bibliography files

In order to create these separate bibliographies using Bookends, we could i. create a library for each bibliography section and sync the references to bibtex; ii. use an Applescript to export different Bookends groups as separate bibliography files. 

Here is a script that will 1. ask for the prefered format, 2. the file extention and then 3. list all front library groups allowing the selection of multiple items. They will be exported to the folder especified in the `BasePath` variable.


[Elephant1]: Elephant1.jpg {#fig-elephant .column-body}

[Elephant2]: Elephant2.jpg  {#fig-castle width=361 height=370}

[Elephant3]: Elephant3.jpg  {#fig-trunk width=455 height=370}

[Elephant3-1]: Elephant3.jpg {#fig-withattributes .myclass fig-align="right" width=3cm height=2cm}

[Elephant1-1]: Elephant1.jpg {#fig-elespan}

[Elephant1-2]: Elephant1.jpg {#fig-elespan3   width= height=}

[Elephant2-1]: Elephant2.jpg  {#fig-castle2 width=361 height=370}

[Elephant3-2]: Elephant3.jpg  {#fig-trunk2 width=454 height=370}

[Elephant3-3]: Elephant3.jpg  {#fig-alignright fig-align="right" width=400 height=324}

[^fn1]: This is a footnote, **with** a citation [@crivellato2007].

[^fn2]: Another footnote. Although footnotes get converted just fine, one caveat is you cannot use Scrivener inline styles, so you **must** use Pandoc markup *directly*.

[^fn3]: A final footnote.
